home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / sun / audio / AudioStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  1.8 KB  |  67 lines

  1. package sun.audio;
  2.  
  3. import java.io.BufferedInputStream;
  4. import java.io.FilterInputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import javax.sound.midi.InvalidMidiDataException;
  8. import javax.sound.midi.MidiFileFormat;
  9. import javax.sound.midi.MidiSystem;
  10. import javax.sound.sampled.AudioFormat;
  11. import javax.sound.sampled.AudioInputStream;
  12. import javax.sound.sampled.AudioSystem;
  13. import javax.sound.sampled.UnsupportedAudioFileException;
  14.  
  15. public class AudioStream extends FilterInputStream {
  16.    protected AudioInputStream ais = null;
  17.    protected AudioFormat format = null;
  18.    protected MidiFileFormat midiformat = null;
  19.    protected InputStream stream = null;
  20.  
  21.    public AudioStream(InputStream var1) throws IOException {
  22.       super(var1);
  23.       this.stream = var1;
  24.       if (!var1.markSupported()) {
  25.          this.stream = new BufferedInputStream(var1, 1024);
  26.       }
  27.  
  28.       try {
  29.          this.ais = AudioSystem.getAudioInputStream(this.stream);
  30.          this.format = this.ais.getFormat();
  31.          this.in = this.ais;
  32.       } catch (UnsupportedAudioFileException var5) {
  33.          try {
  34.             this.midiformat = MidiSystem.getMidiFileFormat(this.stream);
  35.          } catch (InvalidMidiDataException var4) {
  36.             throw new IOException("could not create audio stream from input stream");
  37.          }
  38.       }
  39.  
  40.    }
  41.  
  42.    public AudioData getData() throws IOException {
  43.       int var1 = this.getLength();
  44.       if (var1 < 1048576) {
  45.          byte[] var2 = new byte[var1];
  46.  
  47.          try {
  48.             this.ais.read(var2, 0, var1);
  49.          } catch (IOException var4) {
  50.             throw new IOException("Could not create AudioData Object");
  51.          }
  52.  
  53.          return new AudioData(this.format, var2);
  54.       } else {
  55.          throw new IOException("could not create AudioData object");
  56.       }
  57.    }
  58.  
  59.    public int getLength() {
  60.       if (this.ais != null && this.format != null) {
  61.          return (int)(this.ais.getFrameLength() * (long)this.ais.getFormat().getFrameSize());
  62.       } else {
  63.          return this.midiformat != null ? this.midiformat.getByteLength() : -1;
  64.       }
  65.    }
  66. }
  67.